﻿using System.Text;
using System.Web;
using System.Web.Mvc;

namespace NETMovie.UI.WebMVC.Helpers
{
    public static class MenuHelper
    {
        public static string Menu(this HtmlHelper helper)
        {
            var sb = new StringBuilder();

            // Create opening unordered list tag
            sb.Append("<div class='menu'>");
            sb.AppendFormat("<div class='menuHeader'>{0}</div>", "MENU");
            
            // Render each top level node
            var topLevelNodes = SiteMap.RootNode.ChildNodes;
            foreach (SiteMapNode node in topLevelNodes)
            {
                if (SiteMap.CurrentNode == node)
                    sb.AppendLine("<div class='selectedMenuItem'>");
                else
                    sb.AppendLine("<div class='normalMenuItem'>");

                sb.AppendFormat("<a href='{0}' title='{2}'>&nbsp;&nbsp;|--{1}</a>", node.Url, helper.Encode(node.Title), helper.Encode(node.Description));
                sb.AppendLine("</div>");
            }

            // Close unordered list tag
            sb.Append("</div>");

            return sb.ToString();
        }

    }
}